package cn.jingzhuan.fm.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import cn.jingzhuan.fm.R
import cn.jingzhuan.fm.databinding.ActivityFmAudioDocumentBinding
import cn.jingzhuan.fm.mvp.contract.FMAudioDocumentContract
import cn.jingzhuan.fm.mvp.presenter.FMAudioDocumentPresenter
import cn.jingzhuan.fm.pojo.FMAlbum
import cn.jingzhuan.fm.pojo.FMArticle
import cn.jingzhuan.fm.pojo.FMAudio
import com.zzhoujay.richtext.RichText
import javax.inject.Inject


class FMAudioDocumentActivity : BaseBindingActivity<ActivityFmAudioDocumentBinding>(),FMAudioDocumentContract.View{


    @Inject
    lateinit var fmAudioDocumentPresenter : FMAudioDocumentPresenter
    lateinit var audio: FMAudio
    lateinit var album: FMAlbum

    companion object {

        val ARG_AUDIO = "audio"
        val ARG_ALBUM = "album"

        fun startActivity(context: Context, audio:FMAudio, album:FMAlbum) {
            var intent = Intent(context,FMAudioDocumentActivity::class.java)
            intent.putExtra(ARG_AUDIO,audio)
            intent.putExtra(ARG_ALBUM,album)
            context.startActivity(intent)
        }
    }

    override fun onDataBind(savedInstanceState: Bundle?, binding: ActivityFmAudioDocumentBinding?) {
        audio = intent.getParcelableExtra(ARG_AUDIO)
        album = intent.getParcelableExtra(ARG_ALBUM)
        this.binding.audio = audio
        this.binding.album = album
        this.binding.viewToolbar?.title = "内容详情"
        setUpActionBar(this.binding.viewToolbar?.toolbar)

        initData()
        initListener()
    }

    private fun initListener() {
        this.binding.albumInfo.setOnClickListener {
            FMAlbumDetailActivity.startActivity(this.baseContext,album)
        }
    }

    fun initData() {
        fmAudioDocumentPresenter.articleFind(audio.id)
    }

    override fun getLayoutId(): Int = R.layout.activity_fm_audio_document

    override fun showArticle(article: FMArticle) {
        this.binding.article = article
        RichText.fromHtml(article.content).into(this.binding.audioArticleContent)
    }
}
